<?php
	
	namespace Aspic\Form\Element;
	use Aspic\Security\Security as S;

	/**
	* CheckBox form element
	*/
	class CheckBox extends AbstractStandardElement {

		public function __construct($name, $label = '', $options = array(), array $attributes = array()) {
			parent::__construct($name, $label, $options, $attributes);
			
			$this->attr('checked', false, true);
		}
		
		public function outInput() {
			if(!$this->attr('checked')) {
				$this->removeAttr('checked');
			}
		
			$out = '<input type="checkbox"'.$this->getAttrsAndNameStr().' />';
			
			return $out;
		}
		
		public function bind(array $formData = null) {
			if($this->getValue($formData)) {
				$this->attr('checked', true);
			}
			else {
				$this->attr('checked', false);
			}
		}
		
		protected function getDefaultId() {
			return 'chbx'.ucfirst($this->getName());
		}
		
		
	}
	
?>